/*
 * PaySuccessListItem.java
 * business
 *
 * Created by ChenTao on 2017/2/28.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.yidiandao.business.data.bean.Order;
import com.yidiandao.business.data.response.QueryOrderResultResponse;
import com.yidiandao.business.ui.main.MainActivity;
import com.yidiandao.business.ui.main.home.HomeFragment;
import com.yidiandao.business.ui.orderabout.orderdetail.OrderDetailActivity;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.PaySuccessHolder;

/**
 * 订单支付/购买成功-ListItem
 * <p>
 * <p>Created by ChenTao(chentao7v@gmail.com) on 2017/2/21 16:14
 */
public class PaySuccessListItem extends DisplayListItem<PaySuccessHolder, QueryOrderResultResponse.Data> {

    public PaySuccessListItem(QueryOrderResultResponse.Data s) {
        super(s);
    }

    @Override
    public void onShow(final Context context, PaySuccessHolder holder) {
        holder.refreshUI(data);

        // 去首页逛逛
        holder.tvContinueBuy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity.actionStart((Activity) context, HomeFragment.TAG);
            }
        });

        // 查看订单
        holder.tvShowOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OrderDetailActivity.actionStart((Activity) context, getFirstOrderId(data));
            }
        });
    }

    private String getFirstOrderId(QueryOrderResultResponse.Data data) {
        Order firstOrder = data.getOrderList().get(0);
        return firstOrder.getOrderId();
    }

    @Override
    public String getDisplayItemTag() {
        return PaySuccessListItem.class.getSimpleName();
    }

    @Override
    public Class<PaySuccessHolder> getViewHolderClazz() {
        return PaySuccessHolder.class;
    }
}
